<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用组件的细节点</title>
    <script src="../vue.js"></script>
</head>

<body>
<!--ref获取的内容是组件的引用-->
    <div id="root">
        <counter ref="one" @change="handleChange"></counter>
        <counter ref="two" @change="handleChange"></counter>
        <div>{{total}}</div>
    </div>

    <script>
        Vue.component("counter",{
            template:'<div @click="handleClick">{{number}}</div>',
           data:function () {
                return {number:0}
           },
            methods:{
                handleClick: function () {
                    this.number ++;
                    this.$emit('change');
                }
            }
        });

        var vm = new Vue({
            el:"#root",
            data:{
                total:0
            },
            methods:{
                handleChange:function () {
                    this.total = this.$refs.one.number + this.$refs.two.number;
                }
            }
        })
    </script>

</body>
</html>